package Servlet;

import entity.Orgnazition;
import service.OrgnazitionService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/OrgnazitionServletAdd")
public class OrgnazitionServletAdd extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String name=request.getParameter("name");
        String principalName=request.getParameter("principalName");
        String data=request.getParameter("data");
        Orgnazition orgnazition=new Orgnazition();
        orgnazition.setName(name);
        orgnazition.setPrincipalName(principalName);
        orgnazition.setCreateDate(data);
        OrgnazitionService orgnazitionService=new OrgnazitionService();
        int count=  orgnazitionService.add(orgnazition);
        PrintWriter out= response.getWriter();
        if (count>0){
            out.print("<script> alert('添加成功');location.href='OrgnazitonServlet'</script>");
        }else {
            out.print("<script> alert('添加失败');location.href='OrgnazitonServlet'</script>");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doGet(req,resp);
    }
}
